import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
	redirect:'/login'
  },
  {
    path: '/login',
    name: 'login',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../components/login.vue')
  },
  {
    path: '/home',
    name: 'home',
    component: () => import('../components/Home.vue')
  }
]

const router = new VueRouter({
  routes
})
//路由导航守卫
router.beforeEach((to,form,next) =>{
	if(to.path === '/login') return next();
	let key = sessionStorage.getItem('key')
	if(!key) return next('/login');
	next()
	})

export default router
